/*
 * Config.h
 *
 *  Created on: 2011-7-4
 *      Author: yong
 */

#ifndef CONFIG_H_
#define CONFIG_H_

namespace distrim
{

struct Config
{
	friend class boost::serialization::access;
	friend std::ostream &operator<<(std::ostream &os, const Config &c);
	inline void SetValueElemCount(size_t valueElemCount)
	{
		m_valueElemCount = valueElemCount;
	}

	inline size_t GetValueElemCount() const
	{
		return m_valueElemCount;
	}

	inline void SetClusterNum(size_t clusterNum)
	{
		m_clusterNum = clusterNum;
	}
	inline size_t GetClusterNum() const
	{
		return m_clusterNum;
	}

	inline void SetTotalPoints(size_t totalPoints)
	{
		m_totalPoints = totalPoints;
	}

	inline size_t GetTotalPoints() const
	{
		return m_totalPoints;
	}

	inline void SetConvergeDelta(double convergeDelta)
	{
		m_convergeDelta = convergeDelta;
	}

	inline double GetConvergeDelta() const
	{
		return m_convergeDelta;
	}

	inline void SetMaxIterCount(size_t maxIterCount)
	{
		m_maxIterCount = maxIterCount;
	}

	inline size_t GetMaxIterCount() const
	{
		return m_maxIterCount;
	}

	inline void SetInputPath(const std::string &fileName)
	{
		m_inputPath = fileName;
	}

	inline const std::string &GetInputPath() const
	{
		return m_inputPath;
	}

	inline void SetOutputFileName(const std::string &fileName)
	{
		m_outputFileName = fileName;
	}

	inline const std::string &GetOutputFileName() const
	{
		return m_outputFileName;
	}

	inline void SetIOThreadCount(size_t ioThreadCount)
	{
		m_ioThreadCount = ioThreadCount;
	}

	inline size_t GetIOThreadCount() const
	{
		return m_ioThreadCount;
	}

	inline void SetMapperCount(size_t mapperCount)
	{
		m_mapperCount = mapperCount;
	}

	inline size_t GetMapperCount() const
	{
		return m_mapperCount;
	}

	inline void SetFileSplitsCount(size_t fileSplitsCount)
	{
		m_fileSplitsCount = fileSplitsCount;
	}

	inline size_t GetFileSplitsCount() const
	{
		return m_fileSplitsCount;
	}

	inline void SetInputBufferCount(size_t maxInputBufferCount)
	{
		m_inputBufferCount = maxInputBufferCount;
	}

	inline size_t GetInputBufferCount() const
	{
		return m_inputBufferCount;
	}

	inline void SetPageCapacity(size_t pageCapacity)
	{
		m_pageCapacity = pageCapacity;
	}

	inline size_t GetPageCapacity() const
	{
		return m_pageCapacity;
	}

	inline void SetLocalPoints(size_t localPoints)
	{
		m_localPoints = localPoints;
	}

	inline size_t GetLocalPoints() const
	{
		return m_localPoints;
	}

	inline void SetPreTrainingFile(const std::string &trainingFile)
	{
		m_preTrainingFile = trainingFile;
	}

	inline const std::string &GetPreTrainingFile() const
	{
		return m_preTrainingFile;
	}

private:
	std::string m_inputPath;
	std::string m_outputFileName;
	std::string m_preTrainingFile;
	size_t m_pageCapacity;
	size_t m_fileSplitsCount;
	size_t m_inputBufferCount;
	size_t m_ioThreadCount;
	size_t m_mapperCount;
	size_t m_maxIterCount;
	size_t m_valueElemCount;
	size_t m_clusterNum;
	size_t m_totalPoints;
	size_t m_localPoints;
	double m_convergeDelta;
private:
	template<typename Archive>
	void serialize(Archive &ar, const unsigned int version)
	{
		ar & m_inputPath;
		ar & m_outputFileName;
		ar & m_preTrainingFile;
		ar & m_pageCapacity;
		ar & m_fileSplitsCount;
		ar & m_inputBufferCount;
		ar & m_ioThreadCount;
		ar & m_mapperCount;
		ar & m_maxIterCount;
		ar & m_valueElemCount;
		ar & m_clusterNum;
		ar & m_totalPoints;
		ar & m_localPoints;
		ar & m_convergeDelta;
	}
};

std::ostream &operator<<(std::ostream &os, const Config &c)
{
	os << "Input file: " << c.m_inputPath << std::endl;
	os << "Output file: " << c.m_outputFileName << std::endl;
	os << "Pre-training file: " << c.m_preTrainingFile << std::endl;
	os << "Page capacity: " << c.m_pageCapacity << std::endl;
	os << "File splits: " << c.m_fileSplitsCount << std::endl;
	os << "Input buffer: " << c.m_inputBufferCount << std::endl;
	os << "I/O thread: " << c.m_ioThreadCount << std::endl;
	os << "Mapper: " << c.m_mapperCount << std::endl;
	os << "Max iteration time: " << c.m_maxIterCount << std::endl;
	os << "Dimension: " << c.m_valueElemCount << std::endl;
	os << "Clusters:" << c.m_clusterNum << std::endl;
	os << "Total points:" << c.m_totalPoints << std::endl;
	os << "Local points within one process: " << c.m_localPoints << std::endl;
	os << "Convergence delta: " << c.m_convergeDelta << std::endl;
	return os;
}

}

#endif /* CONFIG_H_ */
